package guoanmaker.operator.business.service;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import guoanmaker.operator.business.model.OperatorOfficeSpace;
import guoanmaker.operator.business.model.ProvideRoom;
import guoanmaker.operator.business.repository.OperatorOfficeSpaceRepository;
import guoanmaker.operator.business.repository.OperatorRoomRepository;
@Service
public class OperatorOfficeSpaceService implements OperatorOfficeSpaceInterface {
	@Autowired
private OperatorOfficeSpaceRepository oeratorOfficeSpaceRepository;
	@Autowired
	private OperatorRoomRepository operatorRoomRepository;
	
	 @PersistenceContext
		private EntityManager manager;
	@Override
	@Transactional
	public OperatorOfficeSpace saveOperatorOfficeSpace(OperatorOfficeSpace operatorOfficeSpace) {
		// TODO Auto-generated method stub
		return oeratorOfficeSpaceRepository.save(operatorOfficeSpace);
	}

	@Override
	public List<OperatorOfficeSpace> getAllOperatorOfficeSpace(String cityId) {
		// TODO Auto-generated method stub
		return oeratorOfficeSpaceRepository.getOperatorOfficeSpace(cityId);
	}

	@Override
	@Transactional
	public void deleteOperatorOfficeSpace(String id) {
		// TODO Auto-generated method stub
		oeratorOfficeSpaceRepository.delete(id);
	}

	@Override
	public List<OperatorOfficeSpace> selectOperatorOfficeSpaceAndroom() {
		List<OperatorOfficeSpace> oospaces=oeratorOfficeSpaceRepository.findAll();
		for(OperatorOfficeSpace oospace:oospaces){
			ProvideRoom provideRoom=	operatorRoomRepository.findByroomCodes(oospace.getRoomCode());
		}
		return null;
	}
	
	
	 @Transactional
	  public void delectAllBycitycode(String cityId){
		  String jpql="delete  from OperatorOfficeSpace  u where u.cityId=:cityId";
		  Query query2=manager.createQuery(jpql);//查询商品提供的服务区域
			query2.setParameter("cityId", cityId);
			query2.executeUpdate();
		  
	  }

}
